/**
 * https://leetcode-cn.com/problems/linked-list-cycle/submissions/
 * Definition for singly-linked list.
 * function ListNode(val) {
 *     this.val = val;
 *     this.next = null;
 * }
 */

/**
 * @param {ListNode} head
 * @return {boolean}
 */
 var hasCycle = function(head) {
    const dummyHead = new ListNode();
    let f = head;
    let s = head;
    let hasCycle = false;
    if (!head) return false;
    while (f && f.next) {
        f = f.next.next;
        s = s.next;
        if (f === s) {
            hasCycle = true;
            break;
        }        
    }
    return hasCycle;
};